//
//  ProductSeriesDetailViewController.m
//  Tiger
//
//  Created by 龚 杰 on 12-7-2.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "ProductSeriesDetailViewController.h"
#import "ASIHTTPRequest.h"
#import <QuartzCore/QuartzCore.h>
@interface ProductSeriesDetailViewController ()

@end

@implementation ProductSeriesDetailViewController
@synthesize m_psimage;
@synthesize m_pseriesimgae;
@synthesize m_pscontent;
@synthesize m_cateID;
@synthesize m_SerDicData;
- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"screen_bg"]]];
    UIScrollView* tScrollContent = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480-88)];
    tScrollContent.tag =0x110;
    [tScrollContent setContentSize:CGSizeMake(320, 610)];
    
    m_pseriesimgae = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
    if (m_psimage!=nil) {
        [self.m_pseriesimgae setImage:m_psimage];
    }
    [tScrollContent addSubview:m_pseriesimgae];
    

    
    UILabel* tCHLabel =[[UILabel alloc] initWithFrame:CGRectMake(8, 210, 300, 22)];
    tCHLabel.backgroundColor =[UIColor clearColor];
    [tCHLabel setTextColor:[UIColor whiteColor]];
    tCHLabel.font = [UIFont boldSystemFontOfSize:20.f];
    tCHLabel.numberOfLines =1;
    tCHLabel.text = [m_SerDicData objectForKey:@"name"];
    [tScrollContent addSubview:tCHLabel];
    [tCHLabel release];
    UILabel* tCHLabel1 =[[UILabel alloc] initWithFrame:CGRectMake(8, 234, 300, 22)];
    tCHLabel1.backgroundColor =[UIColor clearColor];
    [tCHLabel1 setTextColor:[UIColor whiteColor]];
    tCHLabel1.font = [UIFont boldSystemFontOfSize:20.f];
    tCHLabel1.numberOfLines =1;
    tCHLabel1.text = [m_SerDicData objectForKey:@"subname"];
    [tScrollContent addSubview:tCHLabel1];
    [tCHLabel1 release];
    
    UILabel* tENLabel =[[UILabel alloc] initWithFrame:CGRectMake(8, 260, 300, 18)];
    tENLabel.backgroundColor =[UIColor clearColor];
    tENLabel.font = [UIFont systemFontOfSize:16.f];
    [tENLabel setTextColor:[UIColor grayColor]];
    tENLabel.text =[m_SerDicData objectForKey:@"summeryOne"];
    tENLabel.numberOfLines =1;
    [tScrollContent addSubview:tENLabel];
    [tENLabel release];
    UILabel* tENLabel1 =[[UILabel alloc] initWithFrame:CGRectMake(8, 280, 300, 18)];
    tENLabel1.backgroundColor =[UIColor clearColor];
    tENLabel1.font = [UIFont systemFontOfSize:16.f];
    [tENLabel1 setTextColor:[UIColor grayColor]];
    tENLabel1.text =[m_SerDicData objectForKey:@"summeryTow"];
    tENLabel1.numberOfLines =1;
    [tScrollContent addSubview:tENLabel1];
    [tENLabel1 release];
    
    
    p_TLmaterial = [[UILabel alloc] initWithFrame:CGRectMake(8, 306, 70, 18)];
    [p_TLmaterial setTextColor:[UIColor lightGrayColor]];
    [p_TLmaterial setBackgroundColor:[UIColor darkGrayColor]];
    [p_TLmaterial setFont:[UIFont systemFontOfSize:13.f]];
    p_TLmaterial.textAlignment = UITextAlignmentCenter;
    p_TLmaterial.text = @"适用材料";
    p_TLmaterial.layer.cornerRadius =3.f;
    [tScrollContent addSubview:p_TLmaterial];
    
    p_Lmaterial =[[UILabel alloc] initWithFrame:CGRectMake(8, 330, 300, 36)];
    p_Lmaterial.backgroundColor =[UIColor clearColor];
    p_Lmaterial.font = [UIFont systemFontOfSize:16.f];
    [p_Lmaterial setTextColor:[UIColor grayColor]];
    p_Lmaterial.numberOfLines =20;
    [tScrollContent addSubview:p_Lmaterial];

    
    
    p_TLcharacter = [[UILabel alloc] initWithFrame:CGRectMake(8, 370, 70, 18)];
    [p_TLcharacter setTextColor:[UIColor lightGrayColor]];
    [p_TLcharacter setBackgroundColor:[UIColor darkGrayColor]];
    [p_TLcharacter setFont:[UIFont systemFontOfSize:13.f]];
    p_TLcharacter.textAlignment = UITextAlignmentCenter;
    p_TLcharacter.text = @"主要特性";
    p_TLcharacter.layer.cornerRadius =3.f;
    [tScrollContent addSubview:p_TLcharacter];
    
    p_Lcharacter =[[UILabel alloc] initWithFrame:CGRectMake(8, 392, 300, 58)];
    p_Lcharacter.backgroundColor =[UIColor clearColor];
    p_Lcharacter.font = [UIFont systemFontOfSize:16.f];
    [p_Lcharacter setTextColor:[UIColor grayColor]];
    p_Lcharacter.numberOfLines =20;
    [tScrollContent addSubview:p_Lcharacter];

    
    p_TLtexture = [[UILabel alloc] initWithFrame:CGRectMake(8, 430, 70, 18)];
    [p_TLtexture setTextColor:[UIColor lightGrayColor]];
    [p_TLtexture setBackgroundColor:[UIColor darkGrayColor]];
    [p_TLtexture setFont:[UIFont systemFontOfSize:13.f]];
    p_TLtexture.textAlignment = UITextAlignmentCenter;
    p_TLtexture.text = @"材质特性";
    p_TLtexture.layer.cornerRadius =3.f;
    [tScrollContent addSubview:p_TLtexture];
    
    p_Ltexture =[[UILabel alloc] initWithFrame:CGRectMake(8, 450, 300, 36)];
    p_Ltexture.backgroundColor =[UIColor clearColor];
    p_Ltexture.font = [UIFont systemFontOfSize:16.f];
    [p_Ltexture setTextColor:[UIColor grayColor]];
    p_Ltexture.numberOfLines =20;
    [tScrollContent addSubview:p_Ltexture];
    
    
    
    p_TLensure = [[UILabel alloc] initWithFrame:CGRectMake(8, 490, 70, 18)];
    [p_TLensure setTextColor:[UIColor lightGrayColor]];
    [p_TLensure setBackgroundColor:[UIColor darkGrayColor]];
    [p_TLensure setFont:[UIFont systemFontOfSize:13.f]];
    p_TLensure.textAlignment = UITextAlignmentCenter;
    p_TLensure.text = @"品质保证";
    p_TLensure.layer.cornerRadius =3.f;
    [tScrollContent addSubview:p_TLensure];
    
    p_Lensure =[[UILabel alloc] initWithFrame:CGRectMake(8, 510, 300, 36)];
    p_Lensure.backgroundColor =[UIColor clearColor];
    p_Lensure.font = [UIFont systemFontOfSize:16.f];
    [p_Lensure setTextColor:[UIColor grayColor]];
    p_Lensure.numberOfLines =20;
    [tScrollContent addSubview:p_Lensure];
    
    
    p_TLcoat = [[UILabel alloc] initWithFrame:CGRectMake(8, 550, 70, 18)];
    [p_TLcoat setTextColor:[UIColor lightGrayColor]];
    [p_TLcoat setBackgroundColor:[UIColor darkGrayColor]];
    [p_TLcoat setFont:[UIFont systemFontOfSize:13.f]];
    p_TLcoat.textAlignment = UITextAlignmentCenter;
    p_TLcoat.text = @"涂层特色";
    p_TLcoat.layer.cornerRadius =3.f;
    [tScrollContent addSubview:p_TLcoat];
    
    p_Lcoat =[[UILabel alloc] initWithFrame:CGRectMake(8, 570, 300, 36)];
    p_Lcoat.backgroundColor =[UIColor clearColor];
    p_Lcoat.font = [UIFont systemFontOfSize:16.f];
    [p_Lcoat setTextColor:[UIColor grayColor]];
    p_Lcoat.numberOfLines =20;
    [tScrollContent addSubview:p_Lcoat];
    
    
    [self.view addSubview:tScrollContent];
    [tScrollContent release];
    
    NSString* tSerDetailStr = [NSString stringWithFormat:@"http://www.speedtiger.com.cn/ios3/product_show.html?cateID=%d",m_cateID];
    ASIHTTPRequest* tSeriRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:tSerDetailStr]];
    [tSeriRequest setDelegate:self];
    [tSeriRequest startAsynchronous];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (void)dealloc
{
    [p_TLmaterial release];		
    [p_TLcharacter release];		
    [p_TLtexture release];	
    [p_TLensure	 release];	
    [p_TLcoat release];
    [p_Lmaterial release];		
    [p_Lcharacter release];		
    [p_Ltexture release];	
    [p_Lensure release];	
    [p_Lcoat release];
    [m_psimage release];
    [m_pscontent release];
    [m_pseriesimgae release];
    [super dealloc];
}

- (void)requestFinished:(ASIHTTPRequest *)request
{
    NSLog(@"%@",[request responseString]);
    NSData *responseData = [request responseData];
	NSString *responseStr = [[[NSString alloc] initWithData:responseData encoding: NSUTF8StringEncoding] autorelease];

    NSDictionary *dict = [responseStr JSONValue];
    
    int tHeight = 0;
    CGRect aFrame =p_Lmaterial.frame;
    p_Lmaterial.text = [dict objectForKey:@"material"];
    CGSize labelSize = [p_Lmaterial.text sizeWithFont:[UIFont systemFontOfSize:16.f]]; 
    tHeight = ((int)labelSize.width%300 ==0) ?  (int)labelSize.width/300*22:((int)labelSize.width/300+1)*22;
    aFrame.size.height = tHeight;
    p_Lmaterial.frame =aFrame;
    
    aFrame =p_TLcharacter.frame;
    aFrame.origin.y =p_Lmaterial.frame.origin.y+p_Lmaterial.frame.size.height;
    p_TLcharacter.frame = aFrame;
    
    
    p_Lcharacter.text = [dict objectForKey:@"character"];
    NSLog(@"%@",p_Lcharacter.text);
    CGSize labelSize1 = [p_Lcharacter.text sizeWithFont:[UIFont systemFontOfSize:16.f]]; 
    tHeight = ((int)labelSize1.width%300 ==0) ?  (int)labelSize1.width/300*22:((int)labelSize1.width/300+1)*22;
    aFrame =p_Lcharacter.frame;
    aFrame.origin.y =p_TLcharacter.frame.origin.y+p_TLcharacter.frame.size.height+2;
    aFrame.size.height = tHeight;
    p_Lcharacter.frame = aFrame;
    
    aFrame =p_TLtexture.frame;
    aFrame.origin.y =p_Lcharacter.frame.origin.y+p_Lcharacter.frame.size.height;
    p_TLtexture.frame = aFrame;
    
    p_Ltexture.text = [dict objectForKey:@"texture"];
    CGSize labelSize2 = [p_Ltexture.text sizeWithFont:[UIFont systemFontOfSize:16.f]]; 
    tHeight = ((int)labelSize2.width%300 ==0) ?  (int)labelSize2.width/300*22:((int)labelSize2.width/300+1)*22;
    aFrame =p_Ltexture.frame;
    aFrame.origin.y =p_TLtexture.frame.origin.y+p_TLtexture.frame.size.height+2;
    aFrame.size.height = tHeight;
    p_Ltexture.frame = aFrame;
    
    
    aFrame =p_TLensure.frame;
    aFrame.origin.y =p_Ltexture.frame.origin.y+p_Ltexture.frame.size.height;
    p_TLensure.frame = aFrame;
    
    p_Lensure.text = [dict objectForKey:@"ensure"];
    CGSize labelSize3 = [p_Lensure.text sizeWithFont:[UIFont systemFontOfSize:16.f]]; 
    tHeight = ((int)labelSize3.width%300 ==0) ?  (int)labelSize3.width/300*22:((int)labelSize3.width/300+1)*22;
    aFrame =p_Lensure.frame;
    aFrame.origin.y =p_TLensure.frame.origin.y+p_TLensure.frame.size.height+2;
    aFrame.size.height = tHeight;
    p_Lensure.frame = aFrame;
    
    
    aFrame =p_TLcoat.frame;
    aFrame.origin.y =p_Lensure.frame.origin.y+p_Lensure.frame.size.height;
    p_TLcoat.frame = aFrame;
    
    p_Lcoat.text = [dict objectForKey:@"coat"];
    CGSize labelSize4 = [p_Lcoat.text sizeWithFont:[UIFont systemFontOfSize:16.f]]; 
    tHeight = ((int)labelSize4.width%300 ==0) ?  (int)labelSize4.width/300*22:((int)labelSize4.width/300+1)*22;
    aFrame =p_Lcoat.frame;
    aFrame.origin.y =p_TLcoat.frame.origin.y+p_TLcoat.frame.size.height+2;
    aFrame.size.height = tHeight;
    p_Lcoat.frame = aFrame;

    UIScrollView* tScrollContent =(UIScrollView*)[self.view viewWithTag:0x110];
    [tScrollContent setContentSize:CGSizeMake(320, p_Lcoat.frame.origin.y+p_Lcoat.frame.size.height)];
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
	[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
	UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"无可用的网络连接" delegate:self 
										   cancelButtonTitle:nil otherButtonTitles:nil] autorelease];
	[alert addButtonWithTitle:@"确定"];
	[alert show];
}

@end
